//
//  AddHeadPictureCell.m
//  MIDI
//
//  Created by 邵子凡 on 15/11/24.
//  Copyright © 2015年 QXSX. All rights reserved.
//

#import "AddHeadPictureCell.h"
#import "UserDataSingleton.h"
#import "UIImageView+WebCache.h"

@implementation AddHeadPictureCell

+(instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"AddHeadPictureCell";
    
    AddHeadPictureCell  *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"AddHeadPictureCell" owner:nil options:nil]firstObject] ;
    }
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    return cell;
}

- (void)awakeFromNib {
    
    
    //设置按钮图片为圆型
    [self.headImage.layer setCornerRadius:self.headImage.frame.size.width / 2];
    self.headImage.clipsToBounds = YES;
    self.headImage.contentMode = UIViewContentModeScaleAspectFill;
    
    UserDataSingleton * userdata = [UserDataSingleton shareInstance];
    if([userdata isLogin])
    {
        if(userdata.isGotSelfInfo)
        {
            [self.MIDI_ID setText:[@"Midi ID:" stringByAppendingString:userdata.midi_id]];
            NSString *icoUrl = userdata.head_img;
            if(icoUrl == nil || [icoUrl isEqual:@""])
            {
                [self.headImage setImage:[UIImage imageNamed:@"ico_selfinfo_nonoe"] forState:UIControlStateNormal];
            }
            else
            {
                UIImageView *imageView = [[UIImageView alloc] init];
                
                [imageView sd_setImageWithURL:[NSURL URLWithString:userdata.head_img] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
                 {
                     [self.headImage setImage:imageView.image forState:UIControlStateNormal];
                 }];
            }
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
